# 反装数组


class Solution:

    def rotate(self, nums: list[int], k: int):
        # 定义一个反转函数
        def reverse(i: int, j: int):
            while i < j:
                nums[i], nums[j] = nums[j], nums[i]

                i += 1
                j -= 1

        
        n = len(nums)
        # 减少轮转次数
        k %= n

        reverse(0, n - 1)
        reverse(0, k - 1)
        reverse(k, n - 1)


if __name__ == "__main__":

    nums = [1,2,3,4,5,6,7]
    k = 3

    sol = Solution()
    sol.rotate(nums, k)

    print(nums)